﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：RegexAttribute.cs
// 功能描述：TongTongMall.MallWeb
// 
// Create User：jym 2017/02/09
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.ModelBinding;
using TongTongMall.MallWeb.WebApi.Core.ModelBinders;
using TongTongMall.MallWeb.WebApi.Core.ModelBinders.HttpParameterBindings;

namespace TongTongMall.MallWeb.WebApi.Core.ModelBinders.Attributes
{
    public class RegexAttribute  : ParameterBindingAttribute
    {
        public string RegexRules { get; set; }

        public bool IsNot { get; set; }
        /// <summary>
        /// 自定义Model binder处理 datetime
        /// </summary>
        /// <param name="regexRules">正则验证规则</param>
        /// <param name="isnot">是否取反</param>
        public RegexAttribute(string regexRules,bool isnot)
        {
            RegexRules = regexRules;
            IsNot = isnot;
        }

        /// <summary>
        /// 重写参数绑定时间
        /// </summary>
        /// <returns></returns>

        public override HttpParameterBinding GetBinding(HttpParameterDescriptor parameter)
        {
            return new RegexParameterBinding(parameter, RegexRules, IsNot);
        }
    }
}